<?php

use Swostar\Foundation\Application;

/**
 * app函数
 */
if (!function_exists('app')) {
    function app($abstract = null)
    {
        if (empty($abstract)) {
            return Application::getInstance();
        }
        return Application::getInstance()->make($abstract);
    }
}

/**
 * 写入缓存
 * @param mixed $path 
 * @param mixed $content 
 * @param int $type 
 * @param mixed $dir 
 * @return int|false 
 */
function writeCache($path, $content, $type = FILE_APPEND) {
    $dir = dirname($path);
    if (!is_dir($dir)) {
        mkdir($dir, 0777, true);
    }

    !is_string($content) && $content = json_encode($content, JSON_UNESCAPED_UNICODE);
    return file_put_contents($path, $content, $type);
}